from pyquery import PyQuery as pq
import urllib.parse
from module import IndexParser
from module import NodeParser
from module import ContentParser

class Parser(object):
    def paser(self, page_url, html_cont):
        new_urls = set()
        indexparser = IndexParser.Parser()
        nodeparser = NodeParser.Parser()
        contentparser = ContentParser.Parser()

        if page_url is None or html_cont is None or page_url.find('81.cn')==-1:
            return None,html_cont
        doc = pq(html_cont)
        if page_url.find('node_')>-1:
            new_urls,html_cont = nodeparser.paser(page_url,html_cont)
        elif page_url.find('content_')>-1:
            new_urls,html_cont = contentparser.paser(page_url,html_cont)
        else:
            new_urls,html_cont = set(),''
        return new_urls, html_cont
